package crossbreed.tests.diff;

import junit.framework.Assert;
import crossbreed.diff.Diff;
import crossbreed.diff.DiffItem;
import crossbreed.diff.IDiff;
import org.junit.Test;

public class DiffTests
{
	@Test
	public void shouldReturnNoDeletesOrInsertsWhenEqual()
	{
		IDiff diff = new Diff();
		DiffItem[] diffItems = diff.diffText("Test", "Test");
		Assert.assertEquals(0, diffItems.length);
	}
	
	@Test
	public void shouldReturnOneInsertWhenInsertingAtFirstChar()
	{
		IDiff diff = new Diff();
		DiffItem[] diffItems = diff.diffText("Test", "1Test");
		Assert.assertEquals(1, diffItems.length);
		Assert.assertEquals(1, diffItems[0].insertedB);
		Assert.assertEquals(0, diffItems[0].StartB);
	}
	
	@Test
	public void shouldReturnOneInsertWhenInsertingAtLastChar()
	{
		IDiff diff = new Diff();
		DiffItem[] diffItems = diff.diffText("Test", "Test1");
		Assert.assertEquals(1, diffItems.length);
		Assert.assertEquals(1, diffItems[0].insertedB);
	}
	
	@Test
	public void shouldReturnOneDeleteWhenDeletingFirstChar()
	{
		IDiff diff = new Diff();
		DiffItem[] diffItems = diff.diffText("Test", "est");
		Assert.assertEquals(1, diffItems.length);
		Assert.assertEquals(1, diffItems[0].deletedA);
	}
	
	@Test
	public void shouldReturnOneDeleteWhenDeletingLastChar()
	{
		IDiff diff = new Diff();
		DiffItem[] diffItems = diff.diffText("Test", "Tes");
		Assert.assertEquals(1, diffItems.length);
		Assert.assertEquals(1, diffItems[0].deletedA);
	}
}
